<!doctype html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
	<meta name="robots" content="index, follow">
    <link rel="shortcut icon" type="image/png" href="../../../../../../contracts/favicon.png">

<!--	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">-->
	<link rel="stylesheet" type="text/css" href="../../static/css/bootstrap.min.css?9188" th:href="@{/css/bootstrap.min.css?9188}">
	<link rel="stylesheet" type="text/css" href="../../static/css/style.css?8116" th:href="@{/css/style.css?8116}">
	<link rel="stylesheet" type="text/css" href="../../static/css/animate.min.css?7456" th:href="@{/css/animate.min.css?7456}">
	<link href='https://fonts.googleapis.com/css?family=Josefin+Sans&display=swap&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
	<link href='https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900&display=swap&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
    <title>Assign_Permissions</title>


    
<!-- Analytics -->
 
<!-- Analytics END -->
    
</head>
<body>

<!-- Preloader -->
<div id="page-loading-blocs-notifaction" class="page-preloader"></div>
<!-- Preloader END -->


<!-- Main container -->
<div class="page-container">
    
<!-- bloc-0 -->
<div class="bloc l-bloc bgc-azure " id="bloc-0">
	<div class="container bloc-sm">
		<div class="row">
			<div class="col">
				<nav th:replace="_fragments :: nav" class="navbar navbar-light row navbar-expand-md nav-invert" role="navigation">
					<button id="nav-toggle" type="button" class="ui-navbar-toggler navbar-toggler border-0 p-0" data-toggle="collapse" data-target=".navbar-27707" aria-expanded="false" aria-label="Toggle navigation">
						<span class="navbar-toggler-icon"></span>
					</button>
					<div class="collapse navbar-collapse navbar-27707">
						<ul class="site-navigation nav navbar-nav">
							<li class="nav-item">
								<a href="loginup.html" th:href="@{/}" class="nav-link a-btn ltc-white">首页</a>
							</li>
							<li th:if="${session.nowUser.ifHasRight(1)}" class="nav-item">
								<a href="contract/draft.html" th:href="@{/toDraft}" class="nav-link  ltc-white">起草合同</a>
							</li>
							<li th:if="${session.nowUser.ifHasRight(5)}" class="nav-item">
								<a href="select.html" th:href="@{/toCounterSign}" class="nav-link  ltc-white">会签合同</a>
							</li>
							<li th:if="${session.nowUser.ifHasRight(2)}" class="nav-item">
								<a href="finalization.html" th:href="@{/toFinalize}" class="nav-link a-btn ltc-white">定稿合同</a>
							</li>
							<li th:if="${session.nowUser.ifHasRight(6)}" class="nav-item">
								<a href="approval.html" th:href="@{/toExamine}" class="nav-link a-btn ltc-white">审批合同</a>
							</li>
							<li th:if="${session.nowUser.ifHasRight(7)}" class="nav-item">
								<a href="sign.html" th:href="@{/toSign}" class="nav-link a-btn ltc-white">签订合同</a>
							</li>
						</ul>
					</div>
					<a class="navbar-brand mr-0" href="/toMe"> xzx <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" fill="currentColor" class="bi bi-person-fill" viewBox="0 0 16 16"><path d="M3 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1H3zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"/></svg></a>

				</nav>
			</div>
		</div>
	</div>
</div>
<!-- bloc-0 END -->

<!-- bloc-17 -->
<div class="bloc l-bloc" id="bloc-17">
	<div class="container bloc-lg">
		<div class="row">
			<div class="col text-md-left text-center">
				<h1 class="mg-md">
					权限管理
				</h1>
				<h3 class="mg-md" >
					用户名：<span id="username_span" class="text-danger" th:text="${userToAssign.getUsername()}">xxxxx </span>
				</h3>
				<div class="divider-h">
				</div>
				<div class="row">
					<div class="col">
						<div class="card">
							<div class="card-header">
								<h3 class="mg-clear">
									合同管理
								</h3>
							</div>
							<div class="card-body">
								<div class="custom-switch custom-control form-check-inline ">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(1)}? 'checked':'false'" type="checkbox" id="permission1"  />
									<label class="custom-control-label" for="permission1">
										起草合同
									</label>
								</div>
								<div class="custom-switch custom-control">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(2)}? 'checked':'false'" type="checkbox" id="permission2" />
									<label class="custom-control-label" for="permission2">
										定稿合同
									</label>
								</div>
								<div class="custom-switch custom-control">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(3)}? 'checked':'false'" type="checkbox" id="permission3" />
									<label class="custom-control-label" for="permission3">
										查询合同
									</label>
								</div>
								<div class="custom-switch custom-control">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(4)}? 'checked':'false'" type="checkbox" id="permission4" />
									<label class="custom-control-label" for="permission4">
										删除合同
									</label>
								</div>
							</div>
						</div>
					</div>
					<div class="col">
						<div class="card">
							<div class="card-header">
								<h3 class="mg-clear">
									流程管理
								</h3>
							</div>
							<div class="card-body">
								<div class="custom-switch custom-control form-check-inline">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(5)}? 'checked':'false'" type="checkbox" id="permission5" />
									<label class="custom-control-label" for="permission5">
										会签合同
									</label>
								</div>
								<div class="custom-switch custom-control">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(6)}? 'checked':'false'" type="checkbox" id="permission6" />
									<label class="custom-control-label" for="permission6">
										审批合同
									</label>
								</div>
								<div class="custom-switch custom-control">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(7)}? 'checked':'false'" type="checkbox" id="permission7" />
									<label class="custom-control-label" for="permission7">
										签订合同
									</label>
								</div>
							</div>
						</div>
					</div>
					<div class="col">
						<div class="card">
							<div class="card-header">
								<h3 class="mg-clear">
									分配管理
								</h3>
							</div>
							<div class="card-body">
								<div class="custom-switch custom-control form-check-inline">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(8)}? 'checked':'false'" type="checkbox" id="permission8" />
									<label class="custom-control-label" for="permission8">
										分配会签
									</label>
								</div>
								<div class="custom-switch custom-control">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(9)}? 'checked':'false'" type="checkbox" id="permission9" />
									<label class="custom-control-label" for="permission9">
										分配审批
									</label>
								</div>
								<div class="custom-switch custom-control">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(10)}? 'checked':'false'" type="checkbox" id="permission10" />
									<label class="custom-control-label" for="permission10">
										分配签订
									</label>
								</div>
								<div class="custom-switch custom-control">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(11)}? 'checked':'false'" type="checkbox" id="permission11" />
									<label class="custom-control-label" for="permission11">
										流程查询
									</label>
								</div>
							</div>
						</div>
					</div>
					<div class="col">
						<div class="card">
							<div class="card-header">
								<h3 class="mg-clear">
									用户管理
								</h3>
							</div>
							<div class="card-body">
								<div class="custom-switch custom-control form-check-inline">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(12)}? 'checked':'false'" type="checkbox" id="permission12" />
									<label class="custom-control-label" for="permission12">
										新增用户
									</label>
								</div>
								<div class="custom-switch custom-control">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(13)}? 'checked':'false'" type="checkbox" id="permission13" />
									<label class="custom-control-label" for="permission13">
										编辑用户
									</label>
								</div>
								<div class="custom-switch custom-control">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(14)}? 'checked':'false'" type="checkbox" id="permission14" />
									<label class="custom-control-label" for="permission14">
										查询用户
									</label>
								</div>
								<div class="custom-switch custom-control">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(15)}? 'checked':'false'" type="checkbox" id="permission15" />
									<label class="custom-control-label" for="permission15">
										删除用户
									</label>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="divider-h">
					<br><br>
				</div>
				<div class="row">
					<div class="col">
						<div class="card">
							<div class="card-header">
								<h3 class="mg-clear">
									合同客户管理
								</h3>
							</div>
							<div class="card-body">
								<div class="custom-switch custom-control form-check-inline">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(16)}? 'checked':'false'" type="checkbox" id="permission16" />
									<label class="custom-control-label" for="permission16">
										新增客户
									</label>
								</div>
								<div class="custom-switch custom-control">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(17)}? 'checked':'false'" type="checkbox" id="permission17" />
									<label class="custom-control-label" for="permission17">
										编辑客户
									</label>
								</div>
								<div class="custom-switch custom-control">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(18)}? 'checked':'false'" type="checkbox" id="permission18" />
									<label class="custom-control-label" for="permission18">
										查询客户
									</label>
								</div>
								<div class="custom-switch custom-control">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(19)}? 'checked':'false'" type="checkbox" id="permission19" />
									<label class="custom-control-label" for="permission19">
										删除客户
									</label>
								</div>
							</div>
						</div>
					</div>
					<div class="col">
						<div class="card">
							<div class="card-header">
								<h3 class="mg-clear">
									权限配置
								</h3>
							</div>
							<div class="card-body">
								<div class="custom-switch custom-control form-check-inline">
									<input class="custom-control-input" th:checked="${userToAssign.ifHasRight(20)}? 'checked':'false'" type="checkbox" id="permission20" />
									<label class="custom-control-label" for="permission20">
										配置权限
									</label>
								</div>
							</div>
						</div>
					</div>
					<div class="col">
						<span class="empty-column"></span>
					</div>
					<div class="col">
					</div>


				</div>
				<div class="row"><br></div>
				<div class="row"><br></div>
				<div class="row"><br></div>
				<div class="row">
					<div class="col-md-6">

					</div>
					<div class="col-md-2">
						<button  v-on:click="selectAllFunc()" class="bloc-button btn btn-lg btn-block btn-azure btn-保存-style" type="button">
							全选<br>
						</button>
					</div>
					<div class="col-md-2">
						<button v-on:click="reverseSelection()" class="bloc-button btn btn-lg btn-block btn-azure btn-保存-style" type="button">
							反选<br>
						</button>
					</div>
					<div class="col-md-2">
						<button v-on:click="savePermisson()" class="bloc-button btn btn-lg btn-block btn-azure btn-保存-style" type="button">
							保存<br>
						</button>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- bloc-17 END -->

<!-- ScrollToTop Button -->
<a class="bloc-button btn btn-d scrollToTop" onclick="scrollToTarget('1',this)"><svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 32 32"><path class="scroll-to-top-btn-icon" d="M30,22.656l-14-13-14,13"/></svg></a>
<!-- ScrollToTop Button END-->


<!-- bloc-2 -->
<div class="bloc l-bloc" id="bloc-2">
	<div class="container bloc-lg">
		<div class="row">
			<div class="col-12">
				<h5 class="mg-md text-lg-center">
					Thank ♥ You
				</h5>
				<p class="text-lg-center">
					Renxiang Jia,2024
				</p>
			</div>
		</div>
	</div>
</div>
<!-- bloc-2 END -->

</div>
<!-- Main container END -->
    


<!-- Additional JS -->
<script th:src="@{/js/jquery.min.js}" src="../../static/js/jquery.min.js?7482"></script>
<script th:src="@{/js/bootstrap.bundle.min.js?6777}" src="../../static/js/bootstrap.bundle.min.js?6777"></script>
<script th:src="@{/js/blocs.min.js?2512}" src="../../static/js/blocs.min.js?2512"></script>
<script th:src="@{/js/lazysizes.min.js}" src="../../static/js/lazysizes.min.js" defer></script>
<script th:src="@{/js/jquery.min.js}"  type="text/javascript" charset="utf-8"></script>
<script th:src="@{/js/vue.js}"  type="text/javascript" charset="utf-8"></script>
<script th:src="@{/js/axios.min.js}"  type="text/javascript" charset="utf-8"></script>
<script>
	var rightsVue = new Vue({
		el:"#bloc-17",
		data:{//定义数据
			right_num: 20,
			//一些常量
			OK :200
		},
		methods:{
			savePermisson:function (){
				var rights = []; //数组，1表示勾选上权限
				var username =document.getElementById("username_span").innerText;
				//遍历获取用户勾选情况 permission
				var rightsid = "permission";
				for (var i = 1; i <= this.right_num; i++) {
					rightsid += i.toString();
					if ($("#"+rightsid).get(0).checked) {
						rights.push(1);
					}else {
						rights.push(0);
					}
					rightsid = "permission";
				}
				JSON.stringify(rights);
				//发送请求
				axios({
					method: "post",
					url : "/rights/allocationRights",
					params:{username:username},
					data : rights
				}).then(function (value) {
					if(value.data == rightsVue.OK){
						alert("权限更改成功！");
					}else if(value.data == 203){
						alert("当前有未处理合同，无法删除权限，请先处理合同！");
					}
					else{
						alert("权限更改失败！");
					}
				}).catch();
			},

			selectAllFunc: function() {
				var rights = []; //数组，1表示勾选上权限
				var username =document.getElementById("username_span").innerText;
				//遍历获取用户勾选情况 permission
				var rightsid = "permission";
				for (var i = 1; i <= this.right_num; i++) {
					rightsid += i.toString();
					if (!$("#"+rightsid).get(0).checked) {
						$("#"+rightsid).get(0).checked = true
					}
					rightsid = "permission";
				}

			},

			reverseSelection: function() {
				var rights = []; //数组，1表示勾选上权限
				var username =document.getElementById("username_span").innerText;
				//遍历获取用户勾选情况 permission
				var rightsid = "permission";
				for (var i = 1; i <= this.right_num; i++) {
					rightsid += i.toString();
					if ($("#"+rightsid).get(0).checked) {
						$("#"+rightsid).get(0).checked = false;
					} else {
						$("#"+rightsid).get(0).checked = true;
					}
					rightsid = "permission";
				}

			}
		}

	});
</script>


<script>
	function triggerChangeForSelectCustomer(){
		$("#permission1").trigger("change");
		$("#permission2").trigger("change");
		$("#permission3").trigger("change");
		$("#permission4").trigger("change");
		$("#permission11").trigger("change");
		$("#permission13").trigger("change");
		$("#permission14").trigger("change");
		$("#permission15").trigger("change");
		$("#permission17").trigger("change");
		$("#permission18").trigger("change");
		$("#permission19").trigger("change");
		$("#permission20").trigger("change");

	}

	$("#permission13").change(function() {
		if ($("#permission13").get(0).checked)
		{
			$("#permission14").get(0).checked = true;
		}
	});

	$("#permission15").change(function() {
			if ($("#permission15").get(0).checked)
			{
				$("#permission14").get(0).checked = true;
			}
	});



	$("#permission14").change(function() {
		if (($("#permission15").get(0).checked || $("#permission13").get(0).checked) && !$("#permission14").get(0).checked)
		{
			alert("选择编辑或删除用户时，必须保留查询用户权限！");
			$("#permission14").get(0).checked = true;
		}
	});

	$("#permission1").change(function() {
		$("#permission2").get(0).checked = $("#permission1").get(0).checked;
	});

	$("#permission2").change(function() {
		$("#permission1").get(0).checked = $("#permission2").get(0).checked;
	});

	$("#permission17").change(function() {
		if ($("#permission17").get(0).checked)
		{
			$("#permission18").get(0).checked = true;
		}
	});

	$("#permission19").change(function() {
		if ($("#permission19").get(0).checked)
		{
			$("#permission18").get(0).checked = true;
		}
	});

	$("#permission18").change(function() {
		if (($("#permission17").get(0).checked || $("#permission19").get(0).checked) && !$("#permission18").get(0).checked)
		{
			alert("选择编辑或删除客户时，必须保留查询客户权限！");
			$("#permission18").get(0).checked = true;
		}
	});

	$("#permission4").change(function() {
		if ($("#permission4").get(0).checked)
		{
			$("#permission3").get(0).checked = true;
		}
	});

	$("#permission3").change(function() {
		if (($("#permission4").get(0).checked || $("#permission11").get(0).checked) && !$("#permission3").get(0).checked)
		{
			alert("选择删除合同或流程查询时，必须保留查询合同权限！");
			$("#permission3").get(0).checked = true;
		}
	});

	$("#permission11").change(function() {
		if ($("#permission11").get(0).checked)
		{
			$("#permission3").get(0).checked = true;
		}
	});

	$("#permission20").change(function() {
		if ($("#permission20").get(0).checked)
		{
			$("#permission1").get(0).checked = true
			$("#permission2").get(0).checked = true
			$("#permission3").get(0).checked = true
			$("#permission4").get(0).checked = true
			$("#permission5").get(0).checked = true
			$("#permission6").get(0).checked = true
			$("#permission7").get(0).checked = true
			$("#permission8").get(0).checked = true
			$("#permission9").get(0).checked = true
			$("#permission10").get(0).checked = true
			$("#permission11").get(0).checked = true
			$("#permission12").get(0).checked = true
			$("#permission13").get(0).checked = true
			$("#permission14").get(0).checked = true
			$("#permission15").get(0).checked = true
			$("#permission16").get(0).checked = true
			$("#permission17").get(0).checked = true
			$("#permission18").get(0).checked = true
			$("#permission19").get(0).checked = true
		}
	});


</script>


</body>
</html>
